package com.nuanshui.heatedloan.credit.service;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.constant.DubboCacheRegion;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.constant.BankCardType;
import com.nuanshui.heatedloan.credit.dal.mapper.BankCardMapper;
import com.nuanshui.heatedloan.credit.facade.BankCardService;
import com.nuanshui.heatedloan.credit.form.BankCardForm;
import com.nuanshui.heatedloan.credit.vo.BankCardVO;
import com.nuanshui.heatedloan.dubbo.extension.cache.manager.DubboCacheManager;
import com.nuanshui.heatedloan.pageable.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zss
 * @date 2017/7/31 19:17
 * @description
 * @Since
 */
@Service(ServiceConstant.BANKCARDSERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class BankCardServiceImpl implements BankCardService {

    @Autowired
    private BankCardMapper bankCardMapper;

    @Override
    public Pager<BankCardVO> loadBankCard(Pager<BankCardVO> pager) {
        List<BankCardVO> list = bankCardMapper.loadBankCard(pager);
        pager.setData(list);
        return pager;
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public int saveBankCard(BankCardForm bankCardForm) {
        BankCardVO bankCardVO =this.loadBankCardByObject(bankCardForm);
        if(bankCardVO == null ){
            bankCardForm.setStatus(BankCardType.ENABLESTATUS);
            return bankCardMapper.saveBankCard(bankCardForm);
        }
        return 0;
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public boolean updateBankCard(String id, String status) {
        return bankCardMapper.updateBankCard(id,status)>0?true:false;
    }

    @Override
    public BankCardVO loadBankCardByObject(BankCardForm bankCardForm) {
        return bankCardMapper.loadBankCardByObject(bankCardForm);
    }
}
